package com.mitasoft.library;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.mitasoft.business.Book;

public class BooksArrayAdapter extends ArrayAdapter<Book> {

	private Context context;
	private List<Book> books;

	public BooksArrayAdapter(Context context, List<Book> books) {
		super(context, R.layout.list_book, books);

		this.context = context;
		this.books = books;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View rowView = inflater.inflate(R.layout.list_book, parent, false);
		
		TextView titleView = (TextView) rowView.findViewById(R.id.tvBookTitle);
		TextView authorsView = (TextView) rowView.findViewById(R.id.tvBookAuthors);
		TextView publisherView = (TextView) rowView.findViewById(R.id.tvBookPublisher);
		
		Book currentBook = books.get(position);
		
		titleView.setText(currentBook.getTitle());
		authorsView.setText(currentBook.getAuthors());
		publisherView.setText(currentBook.getPublisher());

		return rowView;
	}

}
